<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>垫款冲销 管理</title>
    <style type="text/css">
        .l-box-select-lookup {
            height: 400px;
        }
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <%--<div class="fieldBox">
                    <div class="label">融资项目名称</div>
                    <div class="field">
                        <input name="fncPrjId" id="fncPrjId" type="text" value="">
                    </div>
                </div>--%>
                <div class="fieldBox">
                    <div class="label">支付表号</div>
                    <div class="field">
                        <input name="paySchNo" id="paySchNo" type="text" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">待核销金额</div>
                    <div class="field">
                        <input ligerui="width: 82" name="minAdvClAmt" id="minAdvClAmt" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                        -
                        <input ligerui="width: 82" name="maxAdvClAmt" id="maxAdvClAmt" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                    </div>
                </div>

                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <span id="addBtn" class="sq-button sq-button-round">生成核销指令</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
    <div id="payListGrid" class="sq-grid"></div>

</div>

<script type="text/javascript">
    var rvtFundGrid = null, callback = null, payListGrid = null,batchId = null;

    function getGridOptions(checkbox) {
        var options = {
            url: '<%=path%>/capital/capAdvFundRvt/initFncPrjList.do',
            method : 'get',
            columns: [
                /*{display: 'id', name: 'id', minWidth: 100},*/
                {display: '项目名称', name: 'fncprjnm', minWidth: 100},
                {display: '融资机构', name: 'fncinsNM', minWidth: 100},
                {display: '融资报价', name: 'fncscmNM', minWidth: 100},
                {
                    display: '项目编号', name: 'fncprjid', minWidth: 200,
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        if (value && value != "null") {
                            h += '<a href="javascript:detailBtn(';
                            h += "'" + rowdata.id + "'";
                            h += ')">' + value + '</a>'
                        }
                        return h;
                    },
                },
                {display: '融资资产种类', name: 'astNm', minWidth: 100},
            ], switchPageSizeApplyComboBox: false,
            pageSize: 10,
            root: 'rows',
            record: 'total',
            isSingleCheck:true,
            isScroll: true,
            checkbox: checkbox
        };
        return options;
    }
    var condition = {fields: [{name: 'fncprjnm', label: '项目名称',type: 'text'}]};

    $(function () {
        $("#fncPrjId").ligerComboBox({
            width: 250,
            slide: false,
            selectBoxWidth: 730,
            selectBoxHeight: 420,
            valueField: 'id',
            textField: 'fncprjnm',
            grid: getGridOptions(false),
            condition: condition
        });

        payListGrid = $("#payListGrid").ligerGrid({
            url: '<%=path%>/capital/capAdvFundRvt/initRvtPayList.do',
            method: 'get',
            columns: [
                {display: '支付表号', name: 'paySchNo', minWidth: 100, align: 'left',
                    render:function(rowdata,index,value){
                        return '<a href="javascript:;" style="cursor: pointer;" onclick="">'+rowdata.paySchNo+'</a>';
                    }
                },
                {
                    display: '累计垫款金额', name: 'advAmt', minWidth: 100, align: 'right',
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.advAmt / 100);
                    }
                },
                {
                    display: '累计核销金额', name: 'advClAmt', minWidth: 100, align: 'right',
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.advClAmt / 100);
                    }
                },
                {
                    display: '核销中金额', name: 'payAmt', minWidth: 100, align: 'right',
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.payAmt / 100);
                    }
                },
                {
                    display: '待核销金额', name: 'advClAmt', minWidth: 100, align: 'right',
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney((rowdata.advAmt-rowdata.advClAmt-rowdata.payAmt)/100);
                    }
                },
            ],
            pageSize: 10,
            pageSizeOptions: [10, 30, 50, 100],
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            delayLoad: false
        });
        payListGrid.setHeight(100);

        $("#searchBar").ligerForm();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                payListGrid.setParm(name, data[name]);
            }
            payListGrid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        callback = function () {
            payListGrid.reload();
        };

        /* 生成垫款冲销资金 */
        $("#addBtn").click(function (event) {
            Add_navTab('CapAdvFundRvt_'+ Date.parse(new Date()), "生成垫款冲销指令", '<%=path%>/capital/capAdvFundRvt/toAddPage.do', callback);
        });

        /* 提交垫款冲销 */
        $("#changeBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id = selectedRows[0].id;
            $.ligerDialog.open({
                width: 550,
                height: 500,
                title: '修改垫款资金流水表',
                url: '<%=path%>/capital/capAdvFund/toModifyPage.do?id=' + _id
            });
            //Add_navTab('CapAdvFund_2'+_id, "修改垫款资金流水表", '<%=path%>/capital/capAdvFund/toModifyPage.do?id='+_id, callback);
        });


    });

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    function detailBtn(id){
        Add_navTab('tab_project_detail'+id,'融资项目基本信息','<%=path%>/rfbuss/fncprjbscinfo/toDetailPage1.do?id='+id);
    }

</script>

</body>
</html>
